package com.atguigu.gmall.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@SpringBootApplication
public class ServerGatewayApplication {

   public static void main(String[] args) {
      SpringApplication.run(ServerGatewayApplication.class, args);
   }


   //限流的规则  （按照限流的规则  IP 、接口 、用户)
   @Bean
   public KeyResolver ipKeyResolver(){
      return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
      //return exchange -> Mono.just(exchange.getRequest().getHeaders().getFirst("token"));
      //return exchange -> Mono.just(exchange.getRequest().getPath().value());
//      return new KeyResolver() {
//         @Override
//         public Mono<String> resolve(ServerWebExchange exchange) {
//            return null;
//         }
//      };
   }




}